import { Http, Uploader } from "@/common/HttpClient";
import { Toast, Notify } from "vant";
import { SexEnum, MaritalStatusEnum, EmotionStatusEnum, PictureEnum, IntroduceEnum} from "@/views/mine/enums/PersonInformationEnum";
import { areaList } from "@/assets/arealist/Area.js"
import { getHeightArray , MaritalStatusArray , EmotionStatusArray, EducationLevelArray, WorkIndustryArray, YearlySalaryArray} from "@/views/mine/constants/PersonInformationConstants";
import {ImagePreview} from "vant";

export default {
  data() {
    return {
      userInfo:{
        dataRate:0,
        username:'',
        liveCity:'',
        liveCityName:'',
        homeTownName:'',
        mobile:'',
        platformId:'',
        headPictureUrl: require('@/assets/icon/mine/cat.png'),
        pictures:[],
        introduceList:[],
      },
      IntroduceEnum:IntroduceEnum,
    }
  },
  computed: {

  },
  created() {
      console.log("cableMixincreated")
  },
  mounted() {
      console.log("cableMixinmounted")
  },
  methods: {
    requestUserInfo(){
      let that = this;
      Http.instance()
        .postJSON({
          url: "/makeFriends/sys/user/info",
          params: {
          },
        })
        .then((result) => {
          console.log("用户信息：" + JSON.stringify(result));
          if(result && result['user']){
            this.userInfo = result['user'];
            // this.$set(this.$data, 'saveParam', value)
            this.$set(this.userInfo, 'pictures', []);
            this.$set(this.userInfo, 'introduceList', []);
            if(this.userInfo["headPicture"]){
              this.userInfo["headPictureUrl"] = new Uploader().formatImgPath(this.userInfo["headPicture"]);
            }else {
              this.userInfo["headPictureUrl"] = require('@/assets/icon/mine/cat.png');
            }
            if(this.userInfo["smilePicture"]){
              this.userInfo["smilePicture"] = new Uploader().formatImgPath(this.userInfo["smilePicture"]);
              this.userInfo['pictures'].push(this.userInfo["smilePicture"]);
            }
            if(this.userInfo["lifePicture"]){
              this.userInfo["lifePicture"] = new Uploader().formatImgPath(this.userInfo["lifePicture"]);
              this.userInfo['pictures'].push(this.userInfo["lifePicture"]);
            }
            if(this.userInfo["tripPicture"]){
              this.userInfo["tripPicture"] = new Uploader().formatImgPath(this.userInfo["tripPicture"]);
              this.userInfo['pictures'].push(this.userInfo["tripPicture"]);
            }
            if(this.userInfo["seriousPicture"]){
              this.userInfo["seriousPicture"] = new Uploader().formatImgPath(this.userInfo["seriousPicture"]);
              this.userInfo['pictures'].push(this.userInfo["seriousPicture"]);
            }
            if(this.userInfo["talentPicture"]){
              this.userInfo["talentPicture"] = new Uploader().formatImgPath(this.userInfo["talentPicture"]);
              this.userInfo['pictures'].push(this.userInfo["talentPicture"]);
            }
            if(this.userInfo["petPicture"]){
              this.userInfo["petPicture"] = new Uploader().formatImgPath(this.userInfo["petPicture"]);
              this.userInfo['pictures'].push(this.userInfo["petPicture"]);
            }
            if(this.userInfo['liveCity'] != null){
              this.userInfo['liveCityName'] = areaList['county_list'][this.userInfo['liveCity']];
            }
            if(this.userInfo['homeTown'] != null){
              this.userInfo['homeTownName'] = areaList['county_list'][this.userInfo['homeTown']];
            }
            if(this.userInfo['dataRate'] != null){
              var data = this.userInfo['dataRate'];
              // 1. 计算百分率数值（0.255再乘以100）
              const percentageValue = data* 100;
              // 1. 提取整数部分（向下取整，忽略小数）
              const integerPart = Math.floor(percentageValue); 
              this.userInfo['dataRate']  = integerPart;

            }

            if(this.userInfo['educationLevel'] != null){
              this.userInfo['educationLevelCode'] = this.userInfo['educationLevel'];
              this.userInfo['educationLevelName'] = this.matchArrayName(EducationLevelArray, this.userInfo['educationLevel']);
            }
            if(this.userInfo['workIndustry'] != null){
              this.userInfo['workIndustryCode'] = this.userInfo['workIndustry'];
              this.userInfo['workIndustryName'] = this.matchArrayName(WorkIndustryArray, this.userInfo['workIndustry']);
            }
            if(this.userInfo['yearlySalary'] != null){
              this.userInfo['yearlySalaryCode'] = this.userInfo['yearlySalary'];
              this.userInfo['yearlySalaryName'] = this.matchArrayName(YearlySalaryArray, this.userInfo['yearlySalary']);
            }
            if(this.userInfo['maritalStatus'] != null){
              this.userInfo['maritalStatusCode'] = this.userInfo['maritalStatus'];
              this.userInfo['maritalStatusName'] = this.matchArrayName(MaritalStatusArray, this.userInfo['maritalStatus']);
            }

            this.userInfo['introduceList'] = [];
            if(this.userInfo['height'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['height'] + "cm", "value":IntroduceEnum.HEIGHT});
            }
            if(this.userInfo['constellation'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['constellation'], "value":IntroduceEnum.CONSTELLATION});
            }
            if(this.userInfo['educationLevelName'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['educationLevelName'], "value":IntroduceEnum.EDUCATION_LEVEL});
            }
            if(this.userInfo['workIndustryName'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['workIndustryName'], "value":IntroduceEnum.WORK_INDUSTRY});
            }
            if(this.userInfo['yearlySalaryName'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['yearlySalaryName'], "value":IntroduceEnum.YEARLY_SALARY});
            }
            if(this.userInfo['maritalStatusName'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['maritalStatusName'], "value":IntroduceEnum.MARITAL_STATUS});
            }
            if(this.userInfo['homeTownName'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['homeTownName'], "value":IntroduceEnum.HOME_TOWN});
            }
            if(this.userInfo['liveCityName'] != null){
              this.userInfo['introduceList'].push({"label":this.userInfo['liveCityName'], "value":IntroduceEnum.LIVE_CITY});
            }


          }
        }).catch((result) =>{
          console.log("错误信息：" + result);
          Notify({
            type: "danger",
            message: "" + result,
          });
        });
    },

    
    matchArrayName(arrayList, code){
      var name = "";
      if(arrayList != null){
        for(var i = 0; i < arrayList.length; i++){
          var item = arrayList[i];
          if(item['code'] == code){
            name = item['name'];
          }
        }
      }
      return name;
    },

    matchArrayIndex(arrayList, code){
      var index = 0;
      if(arrayList != null){
        for(var i = 0; i < arrayList.length; i++){
          var item = arrayList[i];
          if(item['code'] == code){
            index = i;
          }
        }
      }
      return index;
    },



  },
}